package com.hmall.order.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderDetail;
import com.hmall.order.pojo.RequestOrder;
import com.hmall.order.service.IOrderService;
import com.hmall.order.service.OrderDetailService;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

   @Autowired
   private OrderDetailService orderDetailService;

   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }

   @PostMapping
    public Long orderBy(@RequestBody RequestOrder order){


      return orderService.orderBy(order);
   }


    /**
     * 根据商品订单id返回订单详情
     * @param orderId
     * @return
     */
    @PostMapping("{id}")
    public OrderDetail findOrderDetailById(@PathVariable("id") Long orderId){
        QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orderId);
        System.out.println(wrapper.toString());
        return orderDetailService.getOne(wrapper);

   }
}
